<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
</head>

<body>
    <!--  v-for,v-if不要放在同一元素中
    下面设计要显示符合条件current=0的项目，不能在li元素中同时写v-for和v-if,可用template结合li使用。
    -->
    <div id="box">
        <ul>
            <template v-for="({title,state},index) of datalist">

          
            <li  v-if="state===current">
                {{title}}---{{index}}

            </li>
          </template>
        </ul>


    </div>
    <script>
        var obj = {
                data() {
                    return {
                        datalist: [{
                            title: '手机',
                            state: 0
                        }, {
                            title: '电脑',
                            state: 1
                        }, {
                            title: '鼠标',
                            state: 2
                        }, {
                            title: '键盘',
                            state: 3
                        }],
                        current: 0
                    }
                },

            }
            // 创建vue实例
        var app = Vue.createApp(obj).mount('#box')
    </script>
</body>

</html>